package sk.naive.talker.command;

/**
 * CommandProxy.
 *
 * @author <a href="mailto:virgo@naive.deepblue.sk">Richard "Virgo" Richter</a>
 * @version $Revision: 1.2 $ $Date: 2005/04/03 07:57:38 $
 */
public class CommandProxy {
	private String commandName;
	private Class<Command> commandClass;
	private boolean configured;

	public CommandProxy(String commandName) {
		this.commandName = commandName;
	}

	public void setCommandClass(Class<Command> commandClass) {
		this.commandClass = commandClass;
		configured = true;
	}

	public String getCommandName() {
		return commandName;
	}

	public Command createCommandInstance() throws IllegalAccessException, InstantiationException {
		if (commandClass == null) {
			throw new InstantiationException("Command class is null for command " + commandName + "!");
		}
		return commandClass.newInstance();
	}

	public void unconfigure() {
		configured = false;
		commandClass = null;
	}

	public boolean isConfigured() {
		return configured;
	}
}
